﻿import com.dmotiko.mirador.*
import com.dmotiko.general.*
import mx.transitions.*;
import mx.transitions.easing.*;
import mx.utils.Delegate;

class MiradorOrganizacionEventos
extends MiradorSiteSection {
	
	public static var MAIN:String = "organizacion_main";
	public static var AMBIENTACION:String = "organizacion_ambientacion";
	public static var MUSICA:String = "organizacion_musica";
	public static var ENTRETENIMIENTOS:String = "organizacion_entretenimientos";
	public static var CALIDAD:String = "organizacion_calidad";
	
	private var nFrameSection:Number;
	private var mcPhotoClip:PhotoClip;
	private var mcNavBar:MiradorOrganizacionNavBar;
	private var mcContent:MovieClip;
	private var sPhotoSrc:String;
	
	function MiradorOrganizacionEventos() {
		super( MiradorSite.getApp() );
		sName = MiradorSite.ORGANIZACION;
		sectionChanged();
	}
	
	private function initClip():Void {
		
	}
	
	private function navbar_changed( evnt ):Void {
		switch( evnt.data ) {
			case MAIN:
			nFrameSection = 2;
			sPhotoSrc = undefined;
			break;
			
			case AMBIENTACION:
			nFrameSection = 3;
			sPhotoSrc = "img/organizacion_ambientacion.jpg";
			break;
			
			case ENTRETENIMIENTOS:
			nFrameSection = 4;
			sPhotoSrc = "img/organizacion_entretenimientos.jpg";
			break;
			
			case MUSICA:
			nFrameSection = 5;
			sPhotoSrc = "img/organizacion_musica.jpg";
			break;
				
			case CALIDAD:
			nFrameSection = 6;
			sPhotoSrc = "img/organizacion_calidad.jpg";
			break;
		}
		registerTween("photoFade", new Tween( mcPhotoClip, "_alpha", Regular.easeOut, mcPhotoClip._alpha, 0, 0.5, true), false, true);
		registerTween("contentFade", new Tween( mcContent, "_alpha", Regular.easeOut, mcContent._alpha, 0, 0.5, true), false, true );
		registerTween("navBarFade", new Tween( mcNavBar, "_alpha", Regular.easeOut, mcNavBar._alpha, 0, 0.5, true), false, true );
	}
		
	public function childLoaded( evnt ):Void {
		switch( evnt.target ) {
			
			case mcPhotoClip:
			mcPhotoClip._alpha = 0;
			break;
			
			case mcNavBar:
			mcNavBar.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, navbar_changed));
			break;
			
		}
	}
	
	private function tweenFinished(key:String, tween:Tween):Void {
		switch( key ) {
			case "contentFade":
			this.gotoAndStop( nFrameSection );
			registerTween("contentFade", new Tween(mcContent, "_alpha", Regular.easeOut, mcContent._alpha, 100, 0.7, true));
			break;
			
			case "navBarFade":
			var nX:Number = mcContent._x + mcContent.mcShadow._x + (mcContent.mcShadow._width - mcNavBar._width) /2 ;
			var nY:Number = mcContent._y + mcContent.mcShadow._y +  mcContent.mcShadow._height - 20;
			mcNavBar._x = nX;
			mcNavBar._y = nY;
			registerTween("navBarFade", new Tween( mcNavBar, "_alpha", Regular.easeOut, mcNavBar._alpha, 100, 0.5, true));
			break;
			
			case "photoFade":
			if ( sPhotoSrc ) {
				mcPhotoClip.setData( sPhotoSrc );
				registerTween("photoFade", new Tween( mcPhotoClip, "_alpha", Regular.easeOut, mcPhotoClip._alpha, 100, 0.5, true))
			}
			break;
			
			default:
			super.tweenFinished(key, tween);
			break;
		}
		
	}
	
}